﻿using HZY.Framework.DependencyInjection;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Long.SpraySCADA
{
    public partial class PageEquipmentMonitor : UIPage, ISingletonSelfDependency
    {
        List<Control> controls;
        public PageEquipmentMonitor()
        {
            InitializeComponent();

            controls = Globals.GetAllControls(this);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (Globals.SiemensClient.Connected)
            {
                foreach (var control in controls)
                {
                    if (control is UserDeviceState userDeviceState)
                    {
                        userDeviceState.State = Globals.DataDicPLC[userDeviceState.VariableName].ToString() == "1";
                    }
                    if (control is UserVarCurrentValue userVarCurrentValue)
                    {
                        userVarCurrentValue.VarValue = Globals.DataDicPLC[userVarCurrentValue.VariableName].ToString().ToFloat();
                    }
                    if (control is UserAlarmState userAlarmState)
                    {
                        //取反，不等于 1 说明报警
                        userAlarmState.State = Globals.DataDicPLC[userAlarmState.VariableName].ToString() != "1";
                    }
                }
            }
            
        }
        #region 窗体切换卡顿
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams paras = base.CreateParams;
                paras.ExStyle |= 0x02000000;
                return paras;
            }
        }
        #endregion
    }
}
